/*
 * Copyright (C) 2023 xuexiangjys(xuexiangjys@163.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.xuexiang.templateproject.utils;

import android.annotation.SuppressLint;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

import com.afollestad.materialdialogs.MaterialDialog;
import com.afollestad.materialdialogs.customview.DialogCustomViewExtKt;
//import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog;
//import com.xuexiang.xui.widget.dialog.bottomsheet.BottomSheet;
//import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog;

import java.util.List;
//import kotlin.Metadata;
import kotlin.jvm.internal.Intrinsics;
//import org.jetbrains.anko.Sdk27PropertiesKt;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.xuexiang.templateproject.R;

public final class DialogManager {
    @SuppressLint({"StaticFieldLeak"})
    @Nullable

    /* renamed from: a  reason: collision with root package name */
    public static MaterialDialog f14224a;

    public interface OnClickListener {
        void a();

        void b();
    }

    public static final void showModeSelect(@NotNull AppCompatActivity appCompatActivity, @NotNull String title, @NotNull String content, @NotNull String leftStr, @NotNull String rightStr, @Nullable List<? extends SpannableString> list, @NotNull final DialogManager.OnClickListener onClickListener) {
        View c2;
//        Intrinsics.checkNotNullParameter(appCompatActivity, "<this>");
//        Intrinsics.checkNotNullParameter(title, "title");
//        Intrinsics.checkNotNullParameter(content, "content");
//        Intrinsics.checkNotNullParameter(leftStr, "leftStr");
//        Intrinsics.checkNotNullParameter(rightStr, "rightStr");
//        Intrinsics.checkNotNullParameter(onClickListener, "onClickListener");
        if (f14224a == null && !appCompatActivity.isFinishing()) {
            MaterialDialog materialDialog = new MaterialDialog(appCompatActivity, null);
            materialDialog.setCancelable(false);
            materialDialog.setCancelOnTouchOutside$core(false);
            materialDialog.cornerRadius(Float.valueOf(10.0f), null);
            DialogCustomViewExtKt.customView(materialDialog, Integer.valueOf((int) R.layout.layout_common_dialog), null, false, false, false, false);
//            MyLifecycleExtKt.a(materialDialog, appCompatActivity);
            f14224a = materialDialog;
            if (!(materialDialog == null || (c2 = DialogCustomViewExtKt.getCustomView(materialDialog)) == null)) {
                ((TextView) c2.findViewById(R.id.tvTitle)).setText(title);
                ((TextView) c2.findViewById(R.id.tvContent)).setText(content);
                ((TextView) c2.findViewById(R.id.tvCancel)).setText(leftStr);
                ((TextView) c2.findViewById(R.id.tvConfirm)).setText(rightStr);
                ((TextView) c2.findViewById(R.id.tvCancel)).setOnClickListener(new View.OnClickListener() { // from class: d.m.b.g.k
                    @Override // android.view.View.OnClickListener
                    public final void onClick(View view) {
                        DialogManager.n(onClickListener, view);
                    }
                });
                ((TextView) c2.findViewById(R.id.tvConfirm)).setOnClickListener(new View.OnClickListener() { // from class: d.m.b.g.r
                    @Override // android.view.View.OnClickListener
                    public final void onClick(View view) {
                        DialogManager.o(onClickListener, view);
                    }
                });
                if (list != null && (!list.isEmpty())) {
                    int size = list.size();
                    for (int i2 = 0; i2 < size; i2++) {
                        ((TextView) c2.findViewById(R.id.tvContent)).append((CharSequence) list.get(i2));
                    }
                    ((TextView) c2.findViewById(R.id.tvContent)).setMovementMethod(LinkMovementMethod.getInstance());
                }
            }
        }
        try {
            MaterialDialog materialDialog2 = f14224a;
            if (materialDialog2 != null) {
                materialDialog2.show();
            }
        } catch (Exception unused) {
        }
    }

    public static final void r(@NotNull AppCompatActivity appCompatActivity, @NotNull String content, @NotNull String leftStr, @NotNull String rightStr, int i2, @NotNull final OnClickListener onClickListener) {

        if (!appCompatActivity.isFinishing()) {
            final MaterialDialog materialDialog = new MaterialDialog(appCompatActivity, null);
            materialDialog.setCancelable(false);
            materialDialog.setCancelOnTouchOutside$core(false);
            materialDialog.cornerRadius(Float.valueOf(10.0f), null);
            DialogCustomViewExtKt.customView(materialDialog, Integer.valueOf((int) R.layout.layout_dialog), null, false, false, false, false);
//            MyLifecycleExtKt.a(materialDialog, appCompatActivity);
            View c2 = DialogCustomViewExtKt.getCustomView(materialDialog);
            ((TextView) c2.findViewById(R.id.tvContent)).setText(content);
            ((TextView) c2.findViewById(R.id.tvCancel)).setText(leftStr);
            ((TextView) c2.findViewById(R.id.tvConfirm)).setText(rightStr);
            if (i2 != 0) {
                ImageView imageView = (ImageView) c2.findViewById(R.id.ivLogo);
                imageView.setVisibility(View.VISIBLE);
//                Intrinsics.checkNotNullExpressionValue(imageView, "imageView");
//                Sdk27PropertiesKt.setImageResource(imageView, i2);
                imageView.setImageResource(i2);
            }
            ((TextView) c2.findViewById(R.id.tvCancel)).setOnClickListener(new View.OnClickListener() { // from class: d.m.b.g.q
                @Override // android.view.View.OnClickListener
                public final void onClick(View view) {
                    DialogManager.s(onClickListener, materialDialog, view);
                }
            });
            ((TextView) c2.findViewById(R.id.tvConfirm)).setOnClickListener(new View.OnClickListener() { // from class: d.m.b.g.j
                @Override // android.view.View.OnClickListener
                public final void onClick(View view) {
                    DialogManager.t(onClickListener, materialDialog, view);
                }
            });
            try {
                materialDialog.show();
            } catch (Exception unused) {
            }
        }
    }

    public static final void n(OnClickListener onClickListener, View view) {
        Intrinsics.checkNotNullParameter(onClickListener, "$onClickListener");
        onClickListener.a();
        MaterialDialog materialDialog = f14224a;
        if (materialDialog != null) {
            materialDialog.dismiss();
        }
        f14224a = null;
    }

    public static final void o(OnClickListener onClickListener, View view) {
        Intrinsics.checkNotNullParameter(onClickListener, "$onClickListener");
        onClickListener.b();
        MaterialDialog materialDialog = f14224a;
        if (materialDialog != null) {
            materialDialog.dismiss();
        }
        f14224a = null;
    }

    public static final void p(OnClickListener onClickListener, View view) {
        Intrinsics.checkNotNullParameter(onClickListener, "$onClickListener");
        onClickListener.a();
        MaterialDialog materialDialog = f14224a;
        if (materialDialog != null) {
            materialDialog.dismiss();
        }
        f14224a = null;
    }

    public static final void q(OnClickListener onClickListener, View view) {
        Intrinsics.checkNotNullParameter(onClickListener, "$onClickListener");
        onClickListener.b();
        MaterialDialog materialDialog = f14224a;
        if (materialDialog != null) {
            materialDialog.dismiss();
        }
        f14224a = null;
    }


    public static final void s(OnClickListener onClickListener, MaterialDialog myDialog, View view) {

        onClickListener.a();
        myDialog.dismiss();
    }

    public static final void t(OnClickListener onClickListener, MaterialDialog myDialog, View view) {

        onClickListener.b();
        myDialog.dismiss();
    }


}